package com.rfid.library.zhongshan;

/// <summary>
    /// 分类号
    /// </summary>
    public class ClassNo
    {
        //#region 字段
        /// <summary>
        /// 分类号内容
        /// </summary>
        String cnStr = null;

        /// <summary>
        /// 分类号长度
        /// </summary>
        int len = 0;
        public ClassNo(String classNo)
        {
            cnStr = classNo;
            len = classNo.length();
        }
        /// <summary>
        /// 按照分类号规则来比较字符大小
        /// </summary>
        /// <param name="c1"> 字符1 </param>
        /// <param name="c2"> 字符2 </param>
        /// <returns> c1 &lt; c2 -1 <br> c1 == c2 0 <br> c1 &gt; c2 1 </returns>
        int compareChar(char c1, char c2)
        {
            String str = "-()（）=“”:#+0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.";

            return str.indexOf(c1) - str.indexOf(c2);
        }

        /// <summary>
        /// 比较分类号
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public int CompareTo(Object o)
        {
//            BookIndex.Fun_Message("分类号比较----------->\r\n");
            ClassNo classNo2 = (ClassNo)o;
            //去掉特殊符号
            String s1 = cnStr.replace("*", "");
            String s2 = classNo2.cnStr.replace("*", "");
            int l1 = s1.length(), l2 = s2.length();

//            if (s1.CompareTo(s2) == 0)
            if (s1.equals(s2))
            {
                return 0;
            }

            int index = 0, tmp;

            while ((l1 > index) && (l2 > index))
            {
                char c1 = s1.charAt(index);
                char c2 = s2.charAt(index);

                tmp = compareChar(c1, c2);

                if (tmp != 0)
                {
                    return tmp;
                }

                index++;
            }

            if ((l1 == index) && (l2 == index))
            {
                return 0;
            }

            if ((l1 == index) && (l2 > index))
            {
                return -1;
            }

            if ((l1 > index) && (l2 == index))
            {
                return 1;
            }

            return 0;
        }
    }